package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.IPrimitive;

public class FactorialPrimitive implements IPrimitive {

	public HobbesTIR apply(HobbesTIR... tir) {
		IntegerTIR arg0 = (IntegerTIR) tir[0];
		int arg1 = arg0.getInt();
		int finalInt = 1;
		for (int i = arg1; i > 0; i--){
			finalInt = finalInt * i;
		}
		return new IntegerTIR(finalInt);
	}

}
